package com.example.testiuh;

import java.util.ArrayList;
import java.util.List;


import android.R.bool;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class Bus_Adapter extends ArrayAdapter<Bus>{

	private  Activity context;
	private int layoutID;
	private ArrayList<Bus> listbus;
	TextView tvname,tvinfo;
	public Bus_Adapter(Activity context, int textViewResourceId,
			ArrayList<Bus> objects) {
		super(context, textViewResourceId, objects);
		this.context=context;
		this.listbus=objects;
		this.layoutID=textViewResourceId;
	}
	public View getView(final int position, View convertView, ViewGroup parent) {	
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(layoutID, null);
		final Bus bus=listbus.get(position);

		final TextView tvname,tvinfo;

		tvname=(TextView) convertView.findViewById(R.id.tvname);
		tvname.setText(bus.getSo()+" <-> "+bus.getname());
		tvinfo=(TextView)convertView.findViewById(R.id.tvinfo);


		tvname.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (tvinfo.getText().toString().trim().equals("")) {
					tvinfo.setText(bus.getBatdau()+"\n"
							+bus.getKetthuc()+"\n"
							+bus.getTuyendi()+"\n"
							+bus.getTuyenve()+"\n");
				}else {
					tvinfo.setText("");
				}
			}
		});
		tvinfo.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				tvinfo.setText("");
			}
		});

		return convertView;
	}
}
